home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / include / sosp.h < prev    next >
C/C++ Source or Header  |  1992-06-21  |  11KB  |  445 lines

  1. /*
  2.  * sospTrace.h --
  3.  *
  4.  *    Declarations of the data structures and constants necessary to
  5.  *    post-process the SOSP 91 file system traces.
  6.  *
  7.  * Copyright 1991 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  *
  16.  * $Header: /sprite/src/lib/sosp/RCS/sosp.h,v 1.2 92/06/21 17:51:19 jhh Exp Locker: mgbaker $ SPRITE (Berkeley)
  17.  */
  18.  
  19. #ifndef _SOSPTRACE
  20. #define _SOSPTRACE
  21.  
  22. /*
  23.  * Relevant portions of the file ID.
  24.  */
  25. typedef struct {
  26.     int        host;
  27.     int        domain;
  28.     int        inode;
  29. } ID;
  30.  
  31. /*
  32.  * File ID specified with relevant portions.
  33.  */
  34. typedef struct {
  35.     int        notused;
  36.     ID        id;
  37. } FileID;
  38.  
  39. /*
  40.  * Beginning of each trace record.
  41.  */
  42. typedef struct    RecordHeader {
  43.     int        flags;        /* See below. */
  44.     int        time[2];    /* (Timer_Ticks) Timestamp. */
  45.     int        type;        /* Type of record that follows. */
  46. } RecordHeader;
  47.  
  48. /*
  49.  * Masks for the flags field in the RecordHeader. 
  50.  */
  51.  
  52. #define TRACELOG_BYTEMASK 0x0000ffff    /* Use this to get the size of the
  53.                      * record. */
  54.  
  55. /*
  56.  * Definitions for the types of log records.  These are the events being
  57.  * traced.
  58.  */
  59. #define SOSP_INVALID            0
  60. #define SOSP_OPEN               1
  61. #define SOSP_DELETE             2
  62. #define SOSP_CREATE             3
  63. #define SOSP_MKLINK             4
  64. #define SOSP_SET_ATTR           5
  65. #define SOSP_GET_ATTR           6
  66. #define SOSP_LSEEK              7
  67. #define SOSP_CLOSE              8
  68. #define SOSP_MIGRATE            9
  69. #define SOSP_TRUNCATE           10
  70. #define SOSP_CONSIST_CHANGE     11
  71. #define SOSP_READ               12
  72. #define SOSP_LOOKUP             13
  73. #define SOSP_CONSIST_ACTION     14
  74. #define SOSP_PREFIX             15
  75. #define SOSP_LOOKUP_OP          16
  76. #define SOSP_DELETE_DESC        17
  77.  
  78. #define SOSP_NUM_EVENTS         18
  79.  
  80. #define    SOSP_LOST_TYPE        128
  81.  
  82. /*
  83.  * Open trace event.
  84.  */
  85. typedef struct {
  86.     RecordHeader        rec;        /* Record info. */
  87.     int                currentHostID;    /* Host doing open. */
  88.     int                homeHostID;    /* Home host if migrated. */
  89.     FileID            fid;        /* File ID being opened. */
  90.     FileID            sid;        /* Stream ID being returned. */
  91.     int                effID;        /* Effective user ID. */
  92.     int                realID;        /* Real user ID. */
  93.     int                mode;        /* Mode the to open the file. */
  94.     int                numNowReading;    /* Number of clients with file
  95.                          * open for reading after
  96.                          * the open. */
  97.     int                numNowWriting;    /* Number of clients with file
  98.                          * open for writing after
  99.                          * the open. */
  100.     int                create;        /* Create time of file. */
  101.     int                size;        /* File size in bytes at open */
  102.     int                modify;        /* Modify time of file. */
  103.     int                type;        /* FS_FILE, FS_DIRECTORY, etc.
  104.                          * See /usr/include/fs.h. */
  105.     int                cacheable;    /* File is cacheable or not. */
  106. } SospOpen;
  107.  
  108. /*
  109.  * Create trace event.
  110.  */
  111. typedef struct {
  112.     RecordHeader        rec;        /* Record info. */
  113.     int                currentHostID;    /* Host doing create. */
  114.     int                homeHostID;    /* Home host if migrated. */
  115.     FileID            fid;        /* File ID created. */
  116. } SospCreate;
  117.  
  118. /*
  119.  * MkLink trace event.
  120.  */
  121. typedef struct {
  122.     RecordHeader        rec;        /* Record info. */
  123.     int                currentHostID;    /* Host doing mklink. */
  124.     int                homeHostID;    /* Home host if migrated. */
  125.     FileID            fid;        /* File ID of link. */
  126. } SospMkLink;
  127.  
  128. /*
  129.  * SetAttr trace event.
  130.  */
  131. typedef struct {
  132.     RecordHeader        rec;        /* Record info. */
  133.     int                currentHostID;    /* Host doing setattr. */
  134.     int                homeHostID;    /* Home host if migrated. */
  135.     FileID            fid;        /* File being set attr'd. */
  136.     int                userID;        /* User doing setattr. */
  137. } SospSetAttr;
  138.  
  139. /*
  140.  * GetAttr trace event.
  141.  */
  142. typedef struct {
  143.     RecordHeader        rec;        /* Record info. */
  144.     int                currentHostID;    /* Host doing getattr. */
  145.     int                homeHostID;    /* Home host if migrated. */
  146.     FileID            fid;        /* File being get attr'd. */
  147.     int                userID;        /* User doing getattr. */
  148. } SospGetAttr;
  149.  
  150.  
  151.  
  152. /*
  153.  * Lseek trace event.
  154.  */
  155. typedef struct {
  156.     RecordHeader        rec;        /* Record info. */
  157.     FileID            sid;        /* Stream ID. */
  158.     int                start;        /* Starting offset. */
  159.     int                end;        /* Ending offset. */
  160.     int                rwflags;    /* R/W flags from stream. */
  161. } SospLseek;
  162.  
  163. /*
  164.  * Close trace event.
  165.  */
  166. typedef struct {
  167.     RecordHeader        rec;        /* Record info. */
  168.     FileID            sid;        /* Stream ID. */
  169.     int                offset;        /* Offset at close time. */
  170.     int                size;        /* Size at close time. */
  171.     int                flags;        /* Flags for stream. */
  172.     int                rwflags;    /* R/W flags for file. */
  173.     int                refCount;    /* Current refs to file. */
  174.     int                consist;    /* Did consistency on close. */
  175. } SospClose;
  176.  
  177. /*
  178.  * Truncation trace event.
  179.  */
  180. typedef struct {
  181.     RecordHeader        rec;        /* Record info. */
  182.     FileID            sid;        /* Stream ID. */
  183.     int                oldLength;    /* Length before trunc. */
  184.     int                newLength;    /* Length after trunc. */
  185.     int                modify;        /* Modify time of file. */
  186.     int                create;        /* Create time of file. */
  187. } SospTrunc;
  188.  
  189. /*
  190.  * Delete trace event.
  191.  */
  192. typedef struct {
  193.     RecordHeader        rec;        /* Record info. */
  194.     int                currentHostID;    /* Host doing open. */
  195.     int                homeHostID;    /* Home host if migrated. */
  196.     FileID            fid;        /* File ID. */
  197.     int                modify;        /* Modify time of file. */
  198.     int                create;        /* Create time of file. */
  199.     int                size;        /* Size of file to delete. */
  200. } SospDelete;
  201.  
  202. /*
  203.  * Consist trace event.
  204.  */
  205. typedef struct {
  206.     RecordHeader        rec;        /* Record info. */
  207.     int                hostID;        /* Host causing consistency
  208.                          * change. */
  209.     FileID            fid;        /* File ID causing consist. */
  210.     int                op;        /* Operation causing the
  211.                          * consist change: SOSP_OPEN,
  212.                          * etc. */
  213.     int                writeOp;    /* Whether operation is for
  214.                          * writing (TRUE) else FALSE. */
  215. } SospConsist;
  216.  
  217. /*
  218.  * Consistency action trace event.
  219.  */
  220. typedef struct {
  221.     RecordHeader        rec;        /* Record info. */
  222.     int            causingHostID;        /* Host causing consistency
  223.                          * change. */
  224.     int            affectedHostID;        /* Host affected by consistency
  225.                          * change. */
  226.     FileID            fid;        /* File ID causing consist. */
  227.     int                action;        /* Whether the action to take
  228.                          * on the client is
  229.                          * FSCONSIST_WRITE_BACK_BLOCKS
  230.                          * and/or
  231.                          * FSCONSIST_INVALIDATE_BLOCKS,
  232.                          * etc. */
  233. } SospConsistAction;
  234.  
  235. /*
  236.  * Read/write trace event on a concurrently write-shared file.
  237.  */
  238. typedef struct {
  239.     RecordHeader        rec;        /* Record info. */
  240.     int                hostID;        /* Host doing read/write. */
  241.     FileID            fid;        /* File ID being read. */
  242.     FileID            sid;        /* Stream ID being read. */
  243.     int                readIt;        /* Whether it's a read (TRUE)
  244.                          * or write (FALSE). */
  245.     int                offset;        /* File offset to start
  246.                          * operation. */
  247.     int                numBytes;    /* Size in bytes to read or
  248.                          * write. */
  249.     int                numNowReading;    /* Number of clients with
  250.                          * file open for reading. */
  251.     int                numNowWriting;    /* Number of clients with
  252.                          * file open for writing. */
  253. } SospRead;
  254.  
  255. /*
  256.  * Prefix operation trace event.
  257.  */
  258. typedef struct {
  259.     RecordHeader        rec;        /* Record info. */
  260.     int                hostID;        /* ID of host. */
  261.     int                rpcID;        /* RPC sequence number. */
  262. } SospAddPrefix;
  263.  
  264.  
  265. /*
  266.  * Migration trace event.
  267.  */
  268. typedef struct {
  269.     RecordHeader        rec;        /* Record info. */
  270.     int                fromHost;    /* Source host of migration. */
  271.     int                toHost;        /* Dest. host of migration. */
  272.     FileID            sid;        /* Stream ID migrated. */
  273.     int                offset;        /* Current offset of stream. */
  274. } SospMigrate;
  275.  
  276. /*
  277.  * Lookup trace event.
  278.  */
  279. typedef struct {
  280.     RecordHeader        rec;        /* Record info. */
  281.     int                currentHostID;    /* Host doing lookup. */
  282.     int                homeHostID;    /* Home host if migrated. */
  283.     FileID            result;        /* FileID result. */
  284.     int                status;        /* Status of lookup:
  285.                          * See FslclLookup. */
  286.     int                size;        /* Number of fileIDs in
  287.                          * buffer space following. */
  288.     int                op;        /* Operation causing lookup:
  289.                          * FS_DOMAIN_OPEN, etc.
  290.                          * See kernel fsNameOps.h. */
  291.     /*
  292.      * Note: the file IDs follow as if in an array immediately after this
  293.      * header.  The size field gives the number of the file IDs.
  294.      */
  295. } SospLookup;
  296.  
  297. /*
  298.  * Delete descriptor trace event.
  299.  */
  300. typedef struct {
  301.     RecordHeader        rec;        /* Record info. */
  302.     FileID            fid;        /* FileID deleted. */
  303.     int                modify;        /* Modify time for file. */
  304.     int                create;        /* Create time for file. */
  305.     int                size;        /* Size of the file. */
  306. } SospDeleteDesc;
  307.  
  308. /*
  309.  * To record number of lost records in the trace.
  310.  */
  311. typedef struct {
  312.     RecordHeader        rec;        /* Record info. */
  313.     int                count;        /* Number of records lost. */
  314. } SospLost;
  315.  
  316.  
  317.  
  318. /***************************************************************************/
  319.  
  320. /*
  321.  *  Structure definition for the trace library routines.
  322.  */
  323.  
  324. typedef struct traceFile {
  325.     FILE *stream;        /* Stream to read from. */
  326.     int traceRecCount;        /* Counter of records read. */
  327.     int numRecs;        /* Counter of number of records. */
  328.     int version;        /* File type version. */
  329.                 /* 0 = old, 1 = new. */
  330.     int swap;            /* 0 = don't, 1 = do. */
  331.     char *name;            /* file name. */
  332. } traceFile;
  333.  
  334. /*
  335.  * Routines provided by the trace library.
  336.  */
  337.  
  338. int initRead _ARGS_((char *name, int argc, char **argv,
  339.     Sys_TracelogHeader **retHdr));
  340. int getHeader _ARGS_((traceFile *file, Sys_TracelogHeader *hdr));
  341. int getNextRecord _ARGS_((traceFile *file, char *buf));
  342. int getNextRecordMerge _ARGS_((char **buf));
  343. Boolean migrateChildren _ARGS_((Boolean flags));
  344.  
  345. /***************************************************************************/
  346.  
  347. /*
  348.  * Definitions for sample post-processor.
  349.  */
  350.  
  351. #define RUN_BUCKET    100
  352. #define OPEN_BUCKET    100
  353. #define SIZE_BUCKET    100
  354. #define AGE_BUCKET    1
  355. #define TPUT_BUCKET    100
  356.  
  357.  
  358. #define WHOLE_FILE 0
  359. #define SEQUENTIAL 1
  360. #define RANDOM 2
  361.  
  362. #define LOW_LIMIT 1000000000
  363.  
  364. #define ID_CMP(a,b)             \
  365.     (!((a.inode == b.inode) &&        \
  366.        (a.domain == b.domain) &&    \
  367.        (a.host == b.host)))
  368.  
  369.  
  370.  
  371. typedef struct {
  372.     int        rwflags;
  373.     int        mig;
  374.     int        histIndex;
  375.     int        user;
  376. } RunHistKey;
  377.  
  378. typedef struct {
  379.     int        mig;
  380.     int        index;
  381. } OpenKey;
  382.  
  383. typedef struct {
  384.     int        state;
  385.     int        usage;
  386.     int        mig;
  387.     int        user;
  388.     int        hour;
  389. } XferKey;
  390.  
  391. typedef struct {
  392.     int        rwflags;
  393.     int        mig;
  394.     int        type;
  395. } TotalBytesKey;
  396.  
  397. typedef struct {
  398.     int        intLength;
  399.     int        index;
  400.     int        user;
  401. } TputKey;
  402.  
  403. typedef struct {
  404.     int        intLength;
  405.     int        index;
  406.     int        user;
  407. } UserKey;
  408.  
  409. typedef struct {
  410.     int            count;
  411.     unsigned int    bytes[2];
  412. } SizeHist, AgeHist, XferHist, RunHist;
  413.  
  414. typedef struct {
  415.     Boolean    mig;
  416.     int        bytes;
  417. } TputHist;
  418.  
  419. typedef struct {
  420.     int        bytes[2];
  421. } TotalBytesInfo;
  422.  
  423. #define ALLOC_VALUE(type, entryPtr) {         \
  424.     char    *__ptr;                \
  425.     __ptr = (char *) malloc(sizeof(type));    \
  426.     bzero((char *) __ptr, sizeof(type));    \
  427.     Hash_SetValue(entryPtr, (Address) __ptr);    \
  428. }
  429.  
  430. #define ADD_TO_VALUE(entryPtr, amount) \
  431.     (Hash_SetValue(entryPtr, (amount) + (unsigned int) Hash_GetValue(entryPtr)))
  432.  
  433. #define ADD_BIG(array, amount) {    \
  434.     array[1] += (amount);        \
  435.     if (array[1] > LOW_LIMIT) {        \
  436.     array[0]++;            \
  437.     array[1] -= LOW_LIMIT;        \
  438.     }                    \
  439. }
  440.  
  441. #define IDSTR(id, str)    \
  442.     sprintf(str, "%x.%x.%x", id.host, id.domain, id.inode)
  443.  
  444. #endif /* _SOSPTRACE */
  445.